﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using starLiGHT;
using Microsoft.Xna.Framework;

namespace starLiGHT.Engine.Tests
{
    [TestFixture]
    public class RectangleF_Tests
    {
        RectangleF rect;

        [SetUp]
        public void Init()
        {
            rect = new RectangleF(10, 11, 12, 13);
        }

        [Test]
        public void Constructor01()
        {
            Rectangle integerRectangle = new Rectangle(10, 11, 12, 13);

            rect = new RectangleF(integerRectangle);

            Assert.AreEqual(integerRectangle.X, rect.X);
            Assert.AreEqual(integerRectangle.Y, rect.Y);
            Assert.AreEqual(integerRectangle.Width, rect.Width);
            Assert.AreEqual(integerRectangle.Height, rect.Height);
        }

        [Test]
        public void Constructor02()
        {
            rect = new RectangleF(new Vector2(10, 11), new Vector2(12, 13));

            Assert.AreEqual(10, rect.X);
            Assert.AreEqual(11, rect.Y);
            Assert.AreEqual(12, rect.Width);
            Assert.AreEqual(13, rect.Height);
        }

        [Test]
        public void Constructor03()
        {
            rect = new RectangleF(new Vector2(10, 11), 12, 13);

            Assert.AreEqual(10, rect.X);
            Assert.AreEqual(11, rect.Y);
            Assert.AreEqual(12, rect.Width);
            Assert.AreEqual(13, rect.Height);
        }

        [Test]
        public void Constructor04()
        {
            rect = new RectangleF(10f, 11f, 12f, 13f);

            Assert.AreEqual(10, rect.X);
            Assert.AreEqual(11, rect.Y);
            Assert.AreEqual(12, rect.Width);
            Assert.AreEqual(13, rect.Height);
        }

        [Test]
        public void Constructor05()
        {
            rect = new RectangleF();
            RectangleF rectEmpty = RectangleF.Empty;

            Assert.AreEqual(rectEmpty.X, rect.X);
            Assert.AreEqual(rectEmpty.Y, rect.Y);
            Assert.AreEqual(rectEmpty.Width, rect.Width);
            Assert.AreEqual(rectEmpty.Height, rect.Height);
        }

        [Test]
        public void Properties01()
        {
            Assert.AreEqual(10, rect.Left);
            Assert.AreEqual(11, rect.Top);
            Assert.AreEqual(22, rect.Right);
            Assert.AreEqual(24, rect.Bottom);

            Assert.AreEqual(new Vector2(10, 11), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);

            Assert.AreEqual(new Vector2(10, 11), rect.TopLeft);
            Assert.AreEqual(new Vector2(22, 24), rect.BottomRight);

            Assert.AreEqual(rect.TopLeft + rect.Size * 0.5f, rect.Center);
        }

        [Test]
        public void Properties02()
        {
            Vector2 test = new Vector2(20, 21);
            rect.BottomRight = test;
            Assert.AreEqual(test, rect.BottomRight);

            rect.TopLeft = test;
            Assert.AreEqual(test, rect.TopLeft);

            rect.Location = test;
            Assert.AreEqual(test, rect.Location);

            rect.Size = test;
            Assert.AreEqual(test, rect.Size);

            Assert.AreEqual(rect.BottomRight - rect.TopLeft, rect.Size);
        }

        [Test]
        public void Properties03()
        {
            Assert.AreEqual(new Vector2(22.0f, 11.0f), rect.TopRight);
            Assert.AreEqual(new Vector2(10.0f, 24.0f), rect.BottomLeft);
        }

        [Test]
        public void Properties04()
        {
            Assert.AreEqual(13.0f, rect.Height);
            Assert.AreEqual(12.0f, rect.Width);
        }

        [Test]
        public void Properties05()
        {
            Vector2[] corners = rect.Corners;
            Assert.AreEqual(4, corners.Length);

            Assert.AreEqual(corners[0], new Vector2(10.0f, 11.0f));
            Assert.AreEqual(corners[1], new Vector2(22.0f, 11.0f));
            Assert.AreEqual(corners[2], new Vector2(22.0f, 24.0f));
            Assert.AreEqual(corners[3], new Vector2(10.0f, 24.0f));
        }

        [Test]
        public void Properties06()
        {
            rect.TopRight = new Vector2(20.0f, 10.0f);

            Vector2[] corners = rect.Corners;
            Assert.AreEqual(4, corners.Length);

            Assert.AreEqual(new Vector2(10.0f, 10.0f), corners[0]);
            Assert.AreEqual(new Vector2(20.0f, 10.0f), corners[1]);
            Assert.AreEqual(new Vector2(20.0f, 24.0f), corners[2]);
            Assert.AreEqual(new Vector2(10.0f, 24.0f), corners[3]);
            Assert.AreEqual(new Vector2(10.0f, 14.0f), rect.Size);
        }

        [Test]
        public void Properties07()
        {
            rect.BottomLeft = new Vector2(10.0f, 20.0f);

            Vector2[] corners = rect.Corners;
            Assert.AreEqual(4, corners.Length);

            Assert.AreEqual(new Vector2(10.0f, 11.0f), corners[0]);
            Assert.AreEqual(new Vector2(22.0f, 11.0f), corners[1]);
            Assert.AreEqual(new Vector2(22.0f, 20.0f), corners[2]);
            Assert.AreEqual(new Vector2(10.0f, 20.0f), corners[3]);
            Assert.AreEqual(new Vector2(12.0f, 9.0f), rect.Size);
        }

        [Test]
        public void Properties08()
        {
            rect = new RectangleF(10.0f, 10.0f, 10.0f, 10.0f);

            rect.Center = new Vector2(30.0f, 30.0f);

            Vector2[] corners = rect.Corners;
            Assert.AreEqual(4, corners.Length);

            Assert.AreEqual(new Vector2(25.0f, 25.0f), corners[0]);
            Assert.AreEqual(new Vector2(35.0f, 25.0f), corners[1]);
            Assert.AreEqual(new Vector2(35.0f, 35.0f), corners[2]);
            Assert.AreEqual(new Vector2(25.0f, 35.0f), corners[3]);
            Assert.AreEqual(new Vector2(10.0f, 10.0f), rect.Size);
        }

        [Test]
        public void IsEmpty01()
        {
            rect = RectangleF.Empty;
            Assert.IsTrue(rect.IsEmpty);

            rect = new RectangleF();
            Assert.IsTrue(rect.IsEmpty);

            rect = new RectangleF(0, 0, 0, 0);
            Assert.IsTrue(rect.IsEmpty);

            rect = new RectangleF(1, 2, 3, 4);
            Assert.IsFalse(rect.IsEmpty);
        }

        [Test]
        public void Members01()
        {
            Assert.AreEqual(10, rect.X);
            Assert.AreEqual(11, rect.Y);
            Assert.AreEqual(12, rect.Width);
            Assert.AreEqual(13, rect.Height);
        }

        [Test]
        public void ToRectangle01()
        {
            Rectangle testRect = new Rectangle(10, 11, 12, 13);
            rect = new RectangleF(testRect);

            Assert.AreEqual(testRect, rect.ToRectangle());
        }

        [Test]
        public void ToOrientedRectangle01()
        {
            OrientedRectangleF testRect = new OrientedRectangleF(10, 11, 12, 13);
            rect = new RectangleF(testRect);

            Assert.AreEqual(testRect, rect.ToOrientedRectangleF());
        }

        [Test]
        public void Scale01()
        {
            //TODO: Check location change...

            rect.Scale(2.0f);
            Assert.AreEqual(3.5f, rect.X);
            Assert.AreEqual(5.0f, rect.Y);
            Assert.AreEqual(2.0f * 12.0f, rect.Width);
            Assert.AreEqual(2.0f * 13.0f, rect.Height);

            rect.Scale(0.5f);
            Assert.AreEqual(10.0f, rect.X);
            Assert.AreEqual(11.0f, rect.Y);
            Assert.AreEqual(12.0f, rect.Width);
            Assert.AreEqual(13.0f, rect.Height);

            rect = new RectangleF(10, 20, 10, 10);
            rect.Scale(new Vector2(2, 3));
            Assert.AreEqual(20, rect.Width);
            Assert.AreEqual(30, rect.Height);
            Assert.AreEqual(0, rect.X);
            Assert.AreEqual(15, rect.Y);
        }

        [Test]
        public void Round01()
        {
            rect = new RectangleF(3.1f, 3.2f, 3.3f, 3.4f);
            rect = rect.Round();

            Assert.AreEqual(3, rect.X);
            Assert.AreEqual(3, rect.Y);
            Assert.AreEqual(3, rect.Width);
            Assert.AreEqual(3, rect.Height);

            rect = new RectangleF(3.4f, 3.5f, 3.6f, 3.7f);
            rect = rect.Round();

            Assert.AreEqual(3, rect.X);
            Assert.AreEqual(4, rect.Y);
            Assert.AreEqual(4, rect.Width);
            Assert.AreEqual(4, rect.Height);
        }

        [Test]
        public void Equals01()
        {
            RectangleF rect1 = new RectangleF(15, 16, 17, 18);
            RectangleF rect2 = new RectangleF(10, 11, 12, 13);
            object test1 = new RectangleF(15, 16, 17, 18);
            object test2 = new RectangleF(10, 11, 12, 13);

            Assert.IsFalse(rect.Equals(rect1));
            Assert.IsFalse(rect.Equals(test1));

            Assert.IsTrue(rect.Equals(rect2));
            Assert.IsTrue(rect.Equals(test2));

            Assert.IsFalse(rect.Equals(new Object()));
        }

        [Test]
        public void Equals02()
        {
            RectangleF rect1 = new RectangleF(15, 16, 17, 18);
            RectangleF rect2 = new RectangleF(10, 11, 12, 13);

            Assert.IsFalse(rect == rect1);
            Assert.IsTrue(rect == rect2);

            Assert.IsTrue(rect != rect1);
            Assert.IsFalse(rect != rect2);
        }

        [Test]
        [Description("codeplex issue #350: RectangleF.Offset not working as expected")]
        public void Offset01()
        {
            Assert.AreEqual(new Vector2(10, 11), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(16, 17.5f), rect.Center);
            rect.Offset(new Point(1, 2));
            Assert.AreEqual(new Vector2(11, 13), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(17, 19.5f), rect.Center);
        }

        [Test]
        [Description("codeplex issue #350: RectangleF.Offset not working as expected")]
        public void Offset02()
        {
            Assert.AreEqual(new Vector2(10, 11), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(16, 17.5f), rect.Center);
            rect.Offset(new Vector2(1, 2));
            Assert.AreEqual(new Vector2(11, 13), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(17, 19.5f), rect.Center);
        }

        [Test]
        [Description("codeplex issue #350: RectangleF.Offset not working as expected")]
        public void Offset03()
        {
            Assert.AreEqual(new Vector2(10, 11), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(16, 17.5f), rect.Center);
            rect.Offset(1f, 2f);
            Assert.AreEqual(new Vector2(11, 13), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(17, 19.5f), rect.Center);
        }

        [Test]
        [Description("codeplex issue #350: RectangleF.Offset not working as expected")]
        public void Offset04()
        {
            Assert.AreEqual(new Vector2(10, 11), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(16, 17.5f), rect.Center);
            rect.Offset(1, 2);
            Assert.AreEqual(new Vector2(11, 13), rect.Location);
            Assert.AreEqual(new Vector2(12, 13), rect.Size);
            Assert.AreEqual(new Vector2(17, 19.5f), rect.Center);
        }

        [Test]
        public void Inflate01()
        {
            rect.Inflate(2f, 3f);

            Assert.AreEqual(8.0f, rect.X);
            Assert.AreEqual(8.0f, rect.Y);
            Assert.AreEqual(16.0f, rect.Width);
            Assert.AreEqual(19.0f, rect.Height);
        }

        [Test]
        public void Contains01()
        {
            System.Collections.Generic.Dictionary<Vector2, Boolean> values = new System.Collections.Generic.Dictionary<Vector2, Boolean>();

            // rect X = 10 .. 20
            // rect Y = 10 .. 20
            rect = new RectangleF(10, 10, 10, 10);

            values.Add(new Vector2(5, 5), false);
            values.Add(new Vector2(10, 5), false);
            values.Add(new Vector2(15, 5), false);
            values.Add(new Vector2(20, 5), false);
            values.Add(new Vector2(25, 5), false);
            values.Add(new Vector2(5, 10), false);
            values.Add(new Vector2(10, 10), true);
            values.Add(new Vector2(15, 10), true);
            values.Add(new Vector2(19, 10), true);
            values.Add(new Vector2(20, 10), false);
            values.Add(new Vector2(25, 10), false);
            values.Add(new Vector2(5, 15), false);
            values.Add(new Vector2(10, 15), true);
            values.Add(new Vector2(15, 15), true);
            values.Add(new Vector2(19, 15), true);
            values.Add(new Vector2(20, 15), false);
            values.Add(new Vector2(25, 15), false);
            values.Add(new Vector2(5, 19), false);
            values.Add(new Vector2(10, 19), true);
            values.Add(new Vector2(15, 19), true);
            values.Add(new Vector2(19, 19), true);
            values.Add(new Vector2(20, 19), false);
            values.Add(new Vector2(25, 19), false);
            values.Add(new Vector2(5, 20), false);
            values.Add(new Vector2(10, 20), false);
            values.Add(new Vector2(15, 20), false);
            values.Add(new Vector2(19, 20), false);
            values.Add(new Vector2(20, 20), false);
            values.Add(new Vector2(25, 20), false);

            foreach (System.Collections.Generic.KeyValuePair<Vector2, Boolean> kvp in values)
            {
                Assert.AreEqual(kvp.Value, rect.Contains(kvp.Key.X, kvp.Key.Y), rect.ToString() + " contains? " + kvp.Key.ToString());
            }
        }

        [Test]
        public void Contains02()
        {
            System.Collections.Generic.Dictionary<Point, Boolean> values = new System.Collections.Generic.Dictionary<Point, Boolean>();

            // rect X = 10 .. 20
            // rect Y = 10 .. 20
            rect = new RectangleF(10, 10, 10, 10);

            values.Add(new Point(5, 5), false);
            values.Add(new Point(10, 5), false);
            values.Add(new Point(15, 5), false);
            values.Add(new Point(20, 5), false);
            values.Add(new Point(25, 5), false);
            values.Add(new Point(5, 10), false);
            values.Add(new Point(10, 10), true);
            values.Add(new Point(15, 10), true);
            values.Add(new Point(19, 10), true);
            values.Add(new Point(20, 10), false);
            values.Add(new Point(25, 10), false);
            values.Add(new Point(5, 15), false);
            values.Add(new Point(10, 15), true);
            values.Add(new Point(15, 15), true);
            values.Add(new Point(19, 15), true);
            values.Add(new Point(20, 15), false);
            values.Add(new Point(25, 15), false);
            values.Add(new Point(5, 19), false);
            values.Add(new Point(10, 19), true);
            values.Add(new Point(15, 19), true);
            values.Add(new Point(19, 19), true);
            values.Add(new Point(20, 19), false);
            values.Add(new Point(25, 19), false);
            values.Add(new Point(5, 20), false);
            values.Add(new Point(10, 20), false);
            values.Add(new Point(15, 20), false);
            values.Add(new Point(19, 20), false);
            values.Add(new Point(20, 20), false);
            values.Add(new Point(25, 20), false);

            foreach (System.Collections.Generic.KeyValuePair<Point, Boolean> kvp in values)
            {
                Assert.AreEqual(kvp.Value, rect.Contains(kvp.Key), rect.ToString() + " contains? " + kvp.Key.ToString());

                Boolean result;
                Point point = kvp.Key;
                rect.Contains(ref point, out result);
                Assert.AreEqual(kvp.Value, result);
            }
        }

        [Test]
        public void Contains03()
        {
            System.Collections.Generic.Dictionary<Vector2, Boolean> values = new System.Collections.Generic.Dictionary<Vector2, Boolean>();

            // rect X = 10 .. 20
            // rect Y = 10 .. 20
            rect = new RectangleF(10, 10, 10, 10);

            values.Add(new Vector2(5, 5), false);
            values.Add(new Vector2(10, 5), false);
            values.Add(new Vector2(15, 5), false);
            values.Add(new Vector2(20, 5), false);
            values.Add(new Vector2(25, 5), false);
            values.Add(new Vector2(5, 10), false);
            values.Add(new Vector2(10, 10), true);
            values.Add(new Vector2(15, 10), true);
            values.Add(new Vector2(19, 10), true);
            values.Add(new Vector2(20, 10), false);
            values.Add(new Vector2(25, 10), false);
            values.Add(new Vector2(5, 15), false);
            values.Add(new Vector2(10, 15), true);
            values.Add(new Vector2(15, 15), true);
            values.Add(new Vector2(19, 15), true);
            values.Add(new Vector2(20, 15), false);
            values.Add(new Vector2(25, 15), false);
            values.Add(new Vector2(5, 19), false);
            values.Add(new Vector2(10, 19), true);
            values.Add(new Vector2(15, 19), true);
            values.Add(new Vector2(19, 19), true);
            values.Add(new Vector2(20, 19), false);
            values.Add(new Vector2(25, 19), false);
            values.Add(new Vector2(5, 20), false);
            values.Add(new Vector2(10, 20), false);
            values.Add(new Vector2(15, 20), false);
            values.Add(new Vector2(19, 20), false);
            values.Add(new Vector2(20, 20), false);
            values.Add(new Vector2(25, 20), false);

            foreach (System.Collections.Generic.KeyValuePair<Vector2, Boolean> kvp in values)
            {
                Assert.AreEqual(kvp.Value, rect.Contains(kvp.Key), rect.ToString() + " contains? " + kvp.Key.ToString());

                Boolean result;
                Vector2 point = kvp.Key;
                rect.Contains(ref point, out result);
                Assert.AreEqual(kvp.Value, result);
            }
        }

        [Test]
        public void Contains04()
        {
            System.Collections.Generic.Dictionary<RectangleF, Boolean> values = new System.Collections.Generic.Dictionary<RectangleF, Boolean>();

            // rect X = 10 .. 20
            // rect Y = 10 .. 20
            rect = new RectangleF(10, 10, 10, 10);

            values.Add(new RectangleF(5, 5, 5, 5), false);
            values.Add(new RectangleF(10, 5, 5, 5), false);
            values.Add(new RectangleF(15, 5, 5, 5), false);
            values.Add(new RectangleF(20, 5, 5, 5), false);
            values.Add(new RectangleF(25, 5, 5, 5), false);
            values.Add(new RectangleF(5, 10, 5, 5), false);
            values.Add(new RectangleF(10, 10, 5, 5), true);
            values.Add(new RectangleF(15, 10, 5, 5), true);
            values.Add(new RectangleF(19, 10, 5, 5), false);
            values.Add(new RectangleF(20, 10, 5, 5), false);
            values.Add(new RectangleF(25, 10, 5, 5), false);
            values.Add(new RectangleF(5, 15, 5, 5), false);
            values.Add(new RectangleF(10, 15, 5, 5), true);
            values.Add(new RectangleF(15, 15, 5, 5), true);
            values.Add(new RectangleF(19, 15, 5, 5), false);
            values.Add(new RectangleF(20, 15, 5, 5), false);
            values.Add(new RectangleF(25, 15, 5, 5), false);
            values.Add(new RectangleF(5, 19, 5, 5), false);
            values.Add(new RectangleF(10, 19, 5, 5), false);
            values.Add(new RectangleF(15, 19, 5, 5), false);
            values.Add(new RectangleF(19, 19, 5, 5), false);
            values.Add(new RectangleF(20, 19, 5, 5), false);
            values.Add(new RectangleF(25, 19, 5, 5), false);
            values.Add(new RectangleF(5, 20, 5, 5), false);
            values.Add(new RectangleF(10, 20, 5, 5), false);
            values.Add(new RectangleF(15, 20, 5, 5), false);
            values.Add(new RectangleF(19, 20, 5, 5), false);
            values.Add(new RectangleF(20, 20, 5, 5), false);
            values.Add(new RectangleF(25, 20, 5, 5), false);

            foreach (System.Collections.Generic.KeyValuePair<RectangleF, Boolean> kvp in values)
            {
                Assert.AreEqual(kvp.Value, rect.Contains(kvp.Key), rect.ToString() + " contains? " + kvp.Key.ToString());

                Boolean result;
                RectangleF testRect = kvp.Key;
                rect.Contains(ref testRect, out result);
                Assert.AreEqual(kvp.Value, result);
            }
        }

        [Test]
        public void Contains05()
        {
            System.Collections.Generic.Dictionary<Rectangle, Boolean> values = new System.Collections.Generic.Dictionary<Rectangle, Boolean>();

            // rect X = 10 .. 20
            // rect Y = 10 .. 20
            rect = new RectangleF(10, 10, 10, 10);

            values.Add(new Rectangle(5, 5, 5, 5), false);
            values.Add(new Rectangle(10, 5, 5, 5), false);
            values.Add(new Rectangle(15, 5, 5, 5), false);
            values.Add(new Rectangle(20, 5, 5, 5), false);
            values.Add(new Rectangle(25, 5, 5, 5), false);
            values.Add(new Rectangle(5, 10, 5, 5), false);
            values.Add(new Rectangle(10, 10, 5, 5), true);
            values.Add(new Rectangle(15, 10, 5, 5), true);
            values.Add(new Rectangle(19, 10, 5, 5), false);
            values.Add(new Rectangle(20, 10, 5, 5), false);
            values.Add(new Rectangle(25, 10, 5, 5), false);
            values.Add(new Rectangle(5, 15, 5, 5), false);
            values.Add(new Rectangle(10, 15, 5, 5), true);
            values.Add(new Rectangle(15, 15, 5, 5), true);
            values.Add(new Rectangle(19, 15, 5, 5), false);
            values.Add(new Rectangle(20, 15, 5, 5), false);
            values.Add(new Rectangle(25, 15, 5, 5), false);
            values.Add(new Rectangle(5, 19, 5, 5), false);
            values.Add(new Rectangle(10, 19, 5, 5), true);
            values.Add(new Rectangle(15, 19, 5, 5), true);
            values.Add(new Rectangle(19, 19, 5, 5), false);
            values.Add(new Rectangle(20, 19, 5, 5), false);
            values.Add(new Rectangle(25, 19, 5, 5), false);
            values.Add(new Rectangle(5, 20, 5, 5), false);
            values.Add(new Rectangle(10, 20, 5, 5), true);
            values.Add(new Rectangle(15, 20, 5, 5), true);
            values.Add(new Rectangle(19, 20, 5, 5), false);
            values.Add(new Rectangle(20, 20, 5, 5), false);
            values.Add(new Rectangle(25, 20, 5, 5), false);

            foreach (System.Collections.Generic.KeyValuePair<Rectangle, Boolean> kvp in values)
            {
                Assert.AreEqual(kvp.Value, rect.Contains(kvp.Key), rect.ToString() + " contains? " + kvp.Key.ToString());

                Boolean result;
                Rectangle testRect = kvp.Key;
                rect.Contains(ref testRect, out result);
                Assert.AreEqual(kvp.Value, result);
            }
        }

        [Test]
        public void FromPoints01()
        {
            Vector2[] testPoints = { new Vector2(5.0f, 3.5f),
                                     new Vector2(10.0f, 5.0f),
                                     new Vector2(15.0f, 5.0f),
                                     new Vector2(20.0f, 5.0f),
                                     new Vector2(25.0f, 5.0f),
                                     new Vector2(5.0f, 10.0f),
                                     new Vector2(10.0f, 10.0f),
                                     new Vector2(15.0f, 10.0f),
                                     new Vector2(20.0f, 10.0f),
                                     new Vector2(25.0f, 10.0f) };

            rect = RectangleF.FromPoints(testPoints);

            Assert.AreEqual(5.0f, rect.X);
            Assert.AreEqual(3.5f, rect.Y);
            Assert.AreEqual(20.0f, rect.Width);
            Assert.AreEqual(6.5f, rect.Height);
        }

        [Test]
        public void Intersect01()
        {
            RectangleF rect1 = new RectangleF(5, 5, 5, 5);
            RectangleF rect2 = new RectangleF(10, 10, 10, 10);

            Assert.AreEqual(RectangleF.Empty, RectangleF.Intersect(rect1, rect2));

            RectangleF result;
            RectangleF.Intersect(ref rect1, ref rect2, out result);
            Assert.AreEqual(RectangleF.Empty, result);
        }

        [Test]
        public void Intersect02()
        {
            RectangleF rect1 = new RectangleF(5, 5, 10, 10);
            RectangleF rect2 = new RectangleF(10, 10, 10, 10);

            Assert.AreEqual(new RectangleF(10, 10, 5, 5), RectangleF.Intersect(rect1, rect2));

            RectangleF result;
            RectangleF.Intersect(ref rect1, ref rect2, out result);
            Assert.AreEqual(new RectangleF(10, 10, 5, 5), result);
        }

        [Test]
        public void Intersects01()
        {
            rect = new RectangleF(10, 10, 5, 5);

            Dictionary<RectangleF, Boolean> testRects = new Dictionary<RectangleF, Boolean>();

            testRects.Add(new RectangleF(0, 0, 5, 5), false);
            testRects.Add(new RectangleF(5, 0, 5, 5), false);
            testRects.Add(new RectangleF(10, 0, 5, 5), false);
            testRects.Add(new RectangleF(15, 0, 5, 5), false);
            testRects.Add(new RectangleF(20, 0, 5, 5), false);

            testRects.Add(new RectangleF(0, 5, 5, 5), false);
            testRects.Add(new RectangleF(5, 5, 5, 5), false);
            testRects.Add(new RectangleF(10, 5, 5, 5), false);
            testRects.Add(new RectangleF(15, 5, 5, 5), false);
            testRects.Add(new RectangleF(20, 5, 5, 5), false);

            testRects.Add(new RectangleF(0, 10, 5, 5), false);
            testRects.Add(new RectangleF(5, 10, 5, 5), false);
            testRects.Add(new RectangleF(10, 10, 5, 5), true);
            testRects.Add(new RectangleF(15, 10, 5, 5), false);
            testRects.Add(new RectangleF(20, 10, 5, 5), false);

            testRects.Add(new RectangleF(0, 15, 5, 5), false);
            testRects.Add(new RectangleF(5, 15, 5, 5), false);
            testRects.Add(new RectangleF(10, 15, 5, 5), false);
            testRects.Add(new RectangleF(15, 15, 5, 5), false);
            testRects.Add(new RectangleF(20, 15, 5, 5), false);

            foreach (KeyValuePair<RectangleF, Boolean> testRect in testRects)
            {
                Assert.AreEqual(testRect.Value, rect.Intersects(testRect.Key), rect.ToString() + " intersects? " + testRect.Key.ToString());

                Boolean result;
                RectangleF r = testRect.Key;
                rect.Intersects(ref r, out result);
                Assert.AreEqual(testRect.Value, result);
            }
        }

        [Test]
        public void Union01()
        {
            RectangleF rect1 = new RectangleF(5, 5, 5, 5);
            RectangleF rect2 = new RectangleF(15, 15, 5, 5);

            RectangleF expected = new RectangleF(5, 5, 15, 15);

            Assert.AreEqual(expected, RectangleF.Union(rect1, rect2));

            RectangleF result;
            RectangleF.Union(ref rect1, ref rect2, out result);
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Union02()
        {
            RectangleF rect1 = new RectangleF(25, 25, 5, 5);
            RectangleF rect2 = new RectangleF(15, 15, 5, 5);

            RectangleF expected = new RectangleF(15, 15, 15, 15);

            Assert.AreEqual(expected, RectangleF.Union(rect1, rect2));

            RectangleF result;
            RectangleF.Union(ref rect1, ref rect2, out result);
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Union03()
        {
            RectangleF rect1 = RectangleF.Empty;
            RectangleF rect2 = rect;

            Assert.AreEqual(rect, RectangleF.Union(rect1, rect2));
        }

        [Test]
        public void Union04()
        {
            RectangleF rect1 = rect;
            RectangleF rect2 = RectangleF.Empty;

            Assert.AreEqual(rect, RectangleF.Union(rect1, rect2));
        }
    }
}